/*
 * Copyright (c) 2011-2014, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: triggerFunction.c 7805 2014-03-13 09:54:35Z geisinger $
 */

/**
 * \file
 *         Source file for function trigger in component pnpTrigger.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (XMT)
 *         (fortiss GmbH).
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "sensorMonitor/adv/pnpTrigger/include/triggerFunction.h"

#include "sensorMonitor/adv/pnpTrigger/include/triggerFunctionWrapper.h"
#include "sensorMonitor/adv/pnpTrigger/include/pnpTriggerComponent.h"
#include "sensorMonitor/adv/pnpTrigger/include/pnpTriggerComponentWrapper.h"
#include "sensorMonitor/adv/pnpTrigger/include/pnpTriggerManifest.h"

#include "xme/core/logUtils.h"

// PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_C_INCLUDES) ENABLED START

#include "sensorMonitor/adv/sensorKB/include/sensorKBManifest.h"

#include "xme/core/plugAndPlay/include/plugAndPlayClient.h"

// PROTECTED REGION END

/******************************************************************************/
/***   Definitions                                                          ***/
/******************************************************************************/

// PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_C_DEFINITIONS) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Variables                                                            ***/
/******************************************************************************/

// PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_C_VARIABLES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/

// PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_C_PROTOTYPES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Implementation                                                       ***/
/******************************************************************************/
xme_status_t
sensorMonitor_adv_pnpTrigger_triggerFunction_init
(
    sensorMonitor_adv_pnpTrigger_pnpTriggerComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_INITIALIZE_C) ENABLED START
    
    // Nothing to do here
    
    XME_UNUSED_PARAMETER(componentConfig);
    
    return XME_STATUS_SUCCESS;
    
    // PROTECTED REGION END
}

void
sensorMonitor_adv_pnpTrigger_triggerFunction_step
(
    sensorMonitor_adv_pnpTrigger_pnpTriggerComponent_config_t* const componentConfig
)
{
    
    {
        // PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_STEP_C) ENABLED START

        static int counter = 50;

        XME_UNUSED_PARAMETER(componentConfig);

        if (48 == counter)
        {
            XME_CHECK_MSG
            (
                XME_STATUS_SUCCESS == xme_core_pnp_pnpClient_instantiateComponentOnThisNode((xme_core_componentType_t)XME_CORE_COMPONENT_TYPE_SENSORKB, NULL),
                XME_CHECK_RVAL_VOID,
                XME_LOG_ERROR,
                "[pnpTrigger] The instantiation of a new component of type sensorKB failed.\n"
            );      
        }
        if (1 == counter)
        {
            XME_CHECK_MSG
            (
                XME_STATUS_SUCCESS == xme_core_pnp_pnpClient_logoutNode(xme_core_node_getCurrentNodeId()), 
                XME_CHECK_RVAL_VOID, 
                XME_LOG_WARNING, 
                "[pnpTrigger] Cannot set the logout request for the node %u.\n",
                xme_core_node_getCurrentNodeId()
            );
        }
        if (0 != counter)
        {
            counter--;
        }
        
        // PROTECTED REGION END
    }
    
    {
        // PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_STEP_2_C) ENABLED START
    
        // TODO: Auto-generated stub
        //       Check return values of writePort calls here
    
        // PROTECTED REGION END
    }
}

void
sensorMonitor_adv_pnpTrigger_triggerFunction_fini
(
    sensorMonitor_adv_pnpTrigger_pnpTriggerComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_TERMINATE_C) ENABLED START
    
    // Nothing to do here
    
    XME_UNUSED_PARAMETER(componentConfig);
    
    // PROTECTED REGION END
}

// PROTECTED REGION ID(SENSORMONITOR_ADV_PNPTRIGGER_TRIGGERFUNCTION_IMPLEMENTATION_C) ENABLED START

// PROTECTED REGION END
